
/*
 * Question: Try to propose an algorithm to find
 * every nodes whose value is 'x'. Then, delete
 * every subtree which are rooted at 'x'.
 *
 * Date: 01/26/2012
 */

#include <iostream>
#include "bitree.h"
using namespace std;

class bitree : public _bitree<bitree, char>
{
};

void delx(bitree *&rt, char x, bool yes)
{
    if (!rt)
        return;
    if (yes || x == rt->key){
        delx(rt->lchild, x, true);
        delx(rt->rchild, x, true);
        delete rt;
        rt = NULL;
    }
    else{
        delx(rt->lchild, x, false);
        delx(rt->rchild, x, false);
    }
}

int main()
{
    bitree *rt;

    bitree_create<bitree,char>(rt, "ex45.txt");
    bitree_print(rt);
    delx(rt, 'D', false);
    bitree_print(rt);
    bitree_destory(rt);

    return 0;
}
